﻿//Copyright © 2012  Daniel Lopez

//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace NASM_Develop_IDE
{
    public partial class FixBrokenProjectDialog : Form
    {
        public FixBrokenProjectDialog()
        {
            InitializeComponent();
        }

        private void solutionPath_MouseDown(object sender, MouseEventArgs e)
        {
            using (OpenFileDialog s = new OpenFileDialog())
            {
                s.Filter = "NASM Solution Format|*.nasmproj";
                if (s.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string fileName =  s.FileName;
                    solutionPath.Text = fileName;
                }
            }
        }

        private void projectFolderPath_MouseDown(object sender, MouseEventArgs e)
        {
            using (FolderBrowserDialog f = new FolderBrowserDialog())
            {
                
                if (f.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    projectFolderPath.Text = f.SelectedPath;
                }
            }
        }

        private void cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void fix_Click(object sender, EventArgs e)
        {
            string sPath = solutionPath.Text;
            
            string pPath = projectFolderPath.Text;
            Solution s = new Solution();
            DirectoryInfo sourcesInfo = new DirectoryInfo(pPath);
            List<string> sources = sourcesInfo.GetFiles("*.asm").ToList().ConvertAll((FileInfo x) => (x.FullName));
            s.AbsolutePathOfBinFolder = pPath + "\\bin";
            s.AbsolutePathOfSources = sources;
            s.NameOfOutputBinary = "default.exe";
            if (Solution.CreateSolution(sPath, s))
            {
                MessageBox.Show("Fixed Project Successfully! If Project Is Still Broken Please Cry For Help!", "Completed",  MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            this.Close();
        }
    }
}
